package user.zc.excel.data.info;


import lombok.Data;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.CellRangeAddress;
import user.zc.excel.data.style.*;

import java.math.BigDecimal;
import java.util.Date;

public interface ICell<T> {

    CellInfo parse(T t);
    @Data
    class CellInfo<T> implements Cloneable{
        private IStyle.StyleInfo styleInfo;
        private int cellType;
        private T data;
        private CellRangeAddress cra ;
        private String mergeRelationColumn;
        private boolean rowSpanIfSameValue;
        @Override
        public CellInfo clone() throws CloneNotSupportedException {
            return (CellInfo)super.clone();
        }
    }

    enum CellType {
        NUMERIC(Cell.CELL_TYPE_NUMERIC, Integer.class, IntegerDataStyle.class),
        STRING(Cell.CELL_TYPE_STRING,String.class, StringDataStyle.class),
        BIGDECIMAL(Cell.CELL_TYPE_NUMERIC, BigDecimal.class, BigDecimalDataStyle.class),
        DATE(Cell.CELL_TYPE_STRING, Date.class, DateDataStyle.class);

        CellType(Integer value,Class clazz,Class style){
            this.value = value;
            this.clazz = clazz;
            this.style = style;
        }
        private Integer value;
        private Class clazz;
        private Class style;

        public Class getStyle() {
            return style;
        }

        public Integer getValue() {
            return value;
        }



        @SneakyThrows
        public static <T extends IStyle> T instanceByClass(Class<?> clazz){
            return (T)byClass(clazz).style.newInstance();
        }

        public static CellType byClass(Class<?> clazz){
            for (CellType value : CellType.values()) {
                if(clazz.equals(value.clazz)){
                    return value;
                }
            }
            return CellType.NUMERIC;
        }
    }
}
